package com.wzw.report;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReportServlet extends HttpServlet {

	private static final long serialVersionUID = 7521720825317434005L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		
		String reportType = req.getParameter("type");
		String projectCode = (String)req.getSession().getAttribute("projectCode");
		
		ReportResult report = null;
		ReportBase reportTool = new ReportImpl();
		reportTool.setModel(req, resp, projectCode);
		if("1".equalsIgnoreCase(reportType)) {
			report = reportTool.getClickSourceReport();
		} else if("2".equalsIgnoreCase(reportType)) {
			report = reportTool.getRegisterSourceReport();
		} else if("3".equalsIgnoreCase(reportType)) {
			report = reportTool.getClickRegisterCompareReport();
		} else if("4".equalsIgnoreCase(reportType)) {
			report = reportTool.getUserCityReport();
		}
		resp.getWriter().write(report.toJSONString());
	}

}
